package com.hezhiqin.formework.aop.aspect;

import com.hezhiqin.formework.aop.intercept.HZQMethodInterceptor;
import com.hezhiqin.formework.aop.intercept.HZQMethodInvocation;

import java.lang.reflect.Method;

/**
 * @program: homeWork
 * @description:
 * @author: hezhiqin
 * @create: 2019-11-06 15:58
 */
public class HZQAfterReturningAdviceInterceptor extends HZQAbstractAspectAdvice implements HZQMethodInterceptor {

    private HZQJoinPoint joinPoint;

    public HZQAfterReturningAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }


    private void afterReturning(Object retVal, Method method, Object[] arguments, Object aThis) throws Throwable {
        super.invokeAdviceMethod(this.joinPoint,retVal,null);
    }

    @Override
    public Object invoke(HZQMethodInvocation invocation) throws Throwable {
        Object retVal = invocation.proceed();
        this.joinPoint = invocation;
        afterReturning(retVal, invocation.getMethod(), invocation.getArguments(),invocation.getThis());
        return retVal;
    }
}
